package com.future;

import com.future.util.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 257. 二叉树的所有路径
 *
 * @author weiruibai.vendor
 * Date: 2022/12/29 14:59
 */
public class Solution_257 {

    private static Solution_257 instance = new Solution_257();

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.left.right = new TreeNode(5);
        root.right = new TreeNode(3);
        List<String> list = instance.binaryTreePaths(root);
        System.out.println(list);
    }

    public List<String> binaryTreePaths(TreeNode root) {
        List<String> ans = new ArrayList<>();
        calcPath(root, ans, "");
        return ans;
    }

    private void calcPath(TreeNode root, List<String> ans, String path) {
        if (root == null) {
            return;
        }
        /**
         * ****
         */
        if (root.left == null && root.right == null) {
            ans.add(path + root.val);
            return;
        }
        path += root.val + "->";
        calcPath(root.left, ans, path);
        calcPath(root.right, ans, path);
    }

}
